#include "TLKSetObjectPos.h"
#include "ObjUsefulFunctions.h"
#include <assert.h>
#include "Game.h"
#include "TimeLineKeyFactory.h"

TLKSetObjectPos::TLKSetObjectPos()
{
	m_ObjID = 0;
}

bool TLKSetObjectPos::Load(File* f)
{
	if(!f->GetInteger(&m_ObjID))
	{
		f->ReportFileError(std::string("Cannot find Object Id"));
		return false;
	}
	
	std::string NewPos;
	if(!f->GetString(&NewPos))
	{
		f->ReportFileError(std::string("Cannot Find New Position"));
		return false;
	}

	Strings strs = Split(NewPos, '/');

	assert(strs.size() == 3);
	
	m_NewPos.m_x = ToFloat(strs[0]);
	m_NewPos.m_y = ToFloat(strs[1]);
	m_NewPos.m_z = ToFloat(strs[2]);
}

void TLKSetObjectPos::Exec()
{
	Vec3f* CurrentPos = TheGame::Instance()->GetObject(m_ObjID)->GetPos();

	*CurrentPos = m_NewPos;
}

TimelineKey* CreateTLKSetObjectPos()
{
	return new TLKSetObjectPos;
}

const char* TLKSetObjectPos::GetTypeName() const
{
	return "TLKSetObjectPos";
}

static bool l = TheTLKFactory::Instance()->AddToMap("TLKSetObjectPos", CreateTLKSetObjectPos);